package lino.node; 
import lino.analysis.*;
import java.io.*;
import java.util.*;
public class Macrosubs extends DepthFirstAdapter {
    public Macrosubs(Hashtable t){  trans=t;}
    
    Hashtable trans  ;
    
    public void defaultOut(  Node node)
    {
      //    map(node,node);
    }
    public Node checkmap(Node n){
        
        
        if(trans.get(n.toString().trim())== null) return n;
        Node n2=(Node)trans.get(n.toString().trim());
       
        return (Node)(n2)   ;
    }
     public void caseABlockAbsexpr(ABlockAbsexpr node)
    {
        // do nothing
    }
    public Node remap(Node n){
        Node n1= deparent(checkmap(n));
        
       // System.out.println("map "+n+"->"+n1);
        return n1;
    }
     Node deparent(Node n){
		 if(n.parent()==null) return n;
		 
		  n.parent(null);
		 
		 return n;
	 }
    public void outAHorizAbsexpr(AHorizAbsexpr node){
         
        node.replaceChild(node.getLeft(), (PAbsexpr) remap(node.getLeft()));
      
        node.replaceChild(node.getRight(), (PAbsexpr)remap(node.getRight()));
        
    }
    public void outARowAbsexpr(ARowAbsexpr node){
        node.replaceChild(node.getAbsexpr(), 
         (PAbsexpr)remap(node.getAbsexpr()));
          
    } 
     public void outARotateAbsexpr(ARotateAbsexpr node){
        node.replaceChild(node.getAbsexpr(),
         (PAbsexpr)remap(node.getAbsexpr())  
        );
       
    }
    public void outAFlipAbsexpr(AFlipAbsexpr node){
         node.replaceChild(node.getAbsexpr(),
         (PAbsexpr)remap(node.getAbsexpr())  
        );
         
    }
      public void outAColAbsexpr(AColAbsexpr node){
         node.replaceChild(node.getAbsexpr(),
         (PAbsexpr)remap(node.getAbsexpr())  
        );
    }
  
     public void outAVertAbsexpr(AVertAbsexpr node){
       
          node.replaceChild(node.getTop(),
         (PAbsexpr)remap(node.getTop())  
            ); 
            node.replaceChild(node.getBottom(),
         (PAbsexpr)remap(node.getBottom())  
        );
    }
  
     

}
